﻿Imports System
Imports System.ComponentModel
Imports System.Runtime.Serialization

<Serializable>
<DataContract(Name:=NameOf(EventPropertyOperationModel))>
Public NotInheritable Class EventPropertyOperationModel
    Implements INotifyPropertyChanged

    ''' <summary>
    ''' What is done to a property when the event is handled
    ''' </summary>
    Public Enum PropertyOperation
        ''' <summary>
        ''' Set the projection property value to the event named property
        ''' </summary>
        SetToValue = 0
        ''' <summary>
        ''' Increment the property as a counter
        ''' </summary>
        IncrementCount = 1
        ''' <summary>
        ''' Decrement the property as a counter
        ''' </summary>
        DecrementCount = 2
        ''' <summary>
        ''' Increment the property by the value of an event's named property
        ''' </summary>
        IncrementByValue = 3
        ''' <summary>
        ''' Decrement the property by the value of an event's named property
        ''' </summary>
        DecrementByValue = 4
        ''' <summary>
        ''' Set a flag status property
        ''' </summary>
        SetFlag = 5
        ''' <summary>
        ''' Unset a flag status property
        ''' </summary>
        UnsetFlag = 6
    End Enum

    Private ReadOnly m_sourcePropertyName As String
    ''' <summary>
    ''' The name of the property of the event that provides the value to use
    ''' </summary>
    ''' <remarks>
    ''' This can be empty if the target is just incremented or decremented by 1
    ''' </remarks>
    Public ReadOnly Property SourcePropertyName As String
        Get
            Return m_sourcePropertyName
        End Get
    End Property

    Private ReadOnly m_targetPropertyName As String
    ''' <summary>
    ''' The name of the property of the projection that is processed 
    ''' </summary>
    Public ReadOnly Property TargetPropertyName As String
        Get
            Return m_targetPropertyName
        End Get
    End Property

    Private m_operation As PropertyOperation
    ''' <summary>
    ''' The operation performed on the source property to update the target property
    ''' </summary>
    Public Property Operation As PropertyOperation
        Get
            Return m_operation
        End Get
        Set(value As PropertyOperation)
            If (m_operation <> value) Then
                m_operation = value
                OnPropertyChanged(NameOf(Operation))
            End If
        End Set
    End Property

#Region "Property Change Notification"
    Public Sub OnPropertyChanged(ByVal propertyName As String)

        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))

    End Sub
    Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
#End Region

    ''' <summary>
    ''' Creates a new model of what happens to a given property when an event is projected
    ''' </summary>
    ''' <param name="sourceProperty">
    ''' The property in the event class that has the value in use in this operation
    ''' </param>
    ''' <param name="targetProperty">
    ''' The property in the projection that is the target of the operation
    ''' </param>
    ''' <param name="operationToPerform">
    ''' The operation to perform for the two properties.  Note that if this is increment by one 
    ''' or decrement by one then the source property is ignored
    ''' </param>
    Public Sub New(ByVal sourceProperty As String, ByVal targetProperty As String, ByVal operationToPerform As PropertyOperation)
        m_sourcePropertyName = sourceProperty
        m_targetPropertyName = targetProperty
        m_operation = operationToPerform
    End Sub

End Class
